package net.zjitc.controller;

import net.zjitc.pojo.Category;
import net.zjitc.pojo.Evaluate;
import net.zjitc.pojo.Product;
import net.zjitc.pojo.User;
import net.zjitc.service.AdminProductService;
import net.zjitc.service.CategoryService;
import net.zjitc.service.impl.AdminProductServiceImpl;
import net.zjitc.service.impl.CategoryServiceImpl;
import net.zjitc.utils.PageBean;
import net.zjitc.utils.dispacher.URLMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Created by Administrator on 2017/12/6.
 */
//用户产品展示
public class UserProduct {
    CategoryService service=new CategoryServiceImpl();
    AdminProductService productService=new AdminProductServiceImpl();
    int pageSize=12;
    //左侧边栏+产品显示
    @URLMapping(url = "/findByCid")
    public String findByCid(HttpServletRequest request, HttpServletResponse response){
        int page=Integer.valueOf(request.getParameter("page"));
        int cid=Integer.valueOf(request.getParameter("cid"));

        //查询到的一级菜单里包含二级菜单列表（左侧边栏）
        List<Category> list=service.findAll();
        request.setAttribute("clist",list);
        //分页查询(根据cid查询一级菜单下的所有产品)
        PageBean<Product> pageBean=productService.findPageByCid(page,pageSize,cid);
        request.setAttribute("page",pageBean);
        //将cid放入request域里
        request.setAttribute("cid",cid);
        //转发到一级菜单列表.jsp
        return "/WEB-INF/user/productList.jsp";
    }

    //左侧边栏+产品显示
    @URLMapping(url = "/findByCsid")
    public String findByCsid(HttpServletRequest request, HttpServletResponse response){
        int page=Integer.valueOf(request.getParameter("page"));
        int csid=Integer.valueOf(request.getParameter("csid"));

        //查询到的一级菜单里包含二级菜单列表（左侧边栏）
        List<Category> list=service.findAll();
        request.setAttribute("clist",list);
        //分页查询(根据csid查询二级菜单所属的所有产品)
        PageBean<Product> pageBean=productService.findPageByCsid(page,pageSize,csid);
        request.setAttribute("page",pageBean);
        //将csid放入request域里
        request.setAttribute("cid",csid);
        //转发到二级菜单列表.jsp
        return "/WEB-INF/user/product_secondList.jsp";
    }

    //产品购买页面
    @URLMapping(url = "/productFindByPid")
    public String productFindByPid(HttpServletRequest request, HttpServletResponse response){
        //通过传入对pid找到产品
        String pid=request.getParameter("pid");
        Product product=productService.findByPid(pid);
        request.setAttribute("pro",product);
        //左侧边栏内容传入
        List<Category> list=service.findAll();
        request.setAttribute("clist",list);
        //评价
        List<Evaluate> evaluateList=productService.findEvaluate(pid);
        request.setAttribute("eva",evaluateList);
        return "/WEB-INF/user/product.jsp";
    }


}
